#include "framelessmdichildwindow.h"
#include "framelessmdimainwindow.h"
#include <QCheckBox>
#include <QRadioButton>
#include <QLineEdit>
#include <QSpinBox>
#include <QComboBox>
#include <QProgressBar>
#include <QTreeWidget>
#include <QHeaderView>
#include <QTableWidget>


framelessChildWidget::framelessChildWidget(QWidget *parent) : QWidget(parent)
{
    setContentsMargins(0,0,0,0);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QGridLayout *grid = new QGridLayout();
    grid->setMargin(10);
    grid->setSpacing(15);
    grid->addWidget(new QLabel("中文字符串"),0,0,1,1);
    grid->addWidget(new QPushButton("中文字符串"),0,1,1,1);
    grid->addWidget(new QCheckBox("中文字符串"),0,2,1,1);
    grid->addWidget(new QRadioButton("中文字符串"),0,3,1,1);

    grid->addWidget(new QLineEdit("中文字符串"),1,0,1,1);
    QSpinBox *editor = new QSpinBox;
    editor->setMinimum(0);
    editor->setMaximum(100);
    grid->addWidget(editor,1,1,1,1);
    QComboBox *combo = new QComboBox;
    combo->addItem("项目1");
    combo->addItem("项目2");
    combo->addItem("项目3");
    grid->addWidget(combo,1,2,1,1);
    QProgressBar *pro = new QProgressBar;
    pro->setRange(0,0);
    grid->addWidget(pro,2,0,1,4);


    QTreeWidget *treeWidget = new QTreeWidget;
    treeWidget->setWindowTitle("树形控件");
    treeWidget->setColumnWidth(0, 200);
    //设定头项名称
    treeWidget->setHeaderLabels(QStringList()<<"键"<<"值");
    //设定各个项
    QTreeWidgetItem* A = new QTreeWidgetItem(QStringList()<<"第一");
    A->setIcon(0, QIcon(":/pic/toolbuttonIcon/checklist.png"));
    A->setCheckState(0, Qt::Checked);
    QTreeWidgetItem* B = new QTreeWidgetItem(QStringList()<<"第二");
    B->setIcon(0, QIcon(":/pic/toolbuttonIcon/checklist.png"));
    B->setCheckState(0, Qt::Unchecked);
    QTreeWidgetItem* C = new QTreeWidgetItem(QStringList()<<"第三");
    C->setIcon(0, QIcon(":/pic/toolbuttonIcon/checklist.png"));
    C->setCheckState(0, Qt::Checked);
    treeWidget->addTopLevelItem(A);
    treeWidget->addTopLevelItem(B);
    treeWidget->addTopLevelItem(C);
    for(int i=0; i<3; ++i)
    {
        QStringList columItemList;
        QTreeWidgetItem *child;
        QString key, value;
        key += "a" + QString::number(i);
        value += QString::number(i);
        columItemList<<key<<value;
        child = new QTreeWidgetItem(columItemList);
        A->addChild(child);
    }
    A->setExpanded(true);

    grid->addWidget(treeWidget,3,0,4,1);


    QTableWidget *tableWidget = new QTableWidget(3,3);

    //设置表头内容
    QStringList header;
    header<<"第一列"<<"第二列"<<"第三列";
    tableWidget->setHorizontalHeaderLabels(header);

    tableWidget->horizontalHeader()->setStretchLastSection(true); //设置充满表宽度
    tableWidget->verticalHeader()->setDefaultSectionSize(12); //设置行高
    tableWidget->verticalHeader()->setVisible(true); //设置垂直头不可见
    tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);  //可多选（Ctrl、Shift、  Ctrl+A都可以）
    tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);  //设置选择行为时每次选择一行
    tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置不可编辑
    tableWidget->horizontalHeader()->resizeSection(0,100); //设置表头第一列的宽度为150
    tableWidget->horizontalHeader()->setFixedHeight(25); //设置表头的高度

    tableWidget->setItem(0,0,new QTableWidgetItem("第一行"));
    tableWidget->setRowHeight(0, 32);
    tableWidget->setItem(1,0,new QTableWidgetItem("第二行"));
    tableWidget->setRowHeight(1, 32);
    tableWidget->setItem(2,0,new QTableWidgetItem("第三行"));
    tableWidget->setRowHeight(2, 32);

    tableWidget->setItem(0,1,new QTableWidgetItem(QIcon(":/pic/toolbuttonIcon/search.png"), "第一行内容"));
    tableWidget->setItem(1,1,new QTableWidgetItem(QIcon(":/pic/toolbuttonIcon/search.png"), "第二行内容"));
    tableWidget->setColumnWidth(1, 150);
    tableWidget->setItem(2,1,new QTableWidgetItem(QIcon(":/pic/toolbuttonIcon/search.png"), "第三行内容"));

    grid->addWidget(tableWidget,3,1,4,3);

    QPushButton *informationBtn = new QPushButton("信息对话框");
    informationBtn->setIcon(QIcon(":/pic/message/information.png"));
    connect(informationBtn, &QPushButton::clicked, this,
            [=]()
            {
                MessageDialog* w = new MessageDialog("标题栏",
                                                     MessageDialog::MSGType::INFORMATION,
                                                     "这是要显示的信息");
                w->setButtonVisualable(MessageDialog::DialogButton::REJECT, false);
                w->show();
            });
    grid->addWidget(informationBtn,8,1,1,1);

    QPushButton *alertBtn = new QPushButton("警告对话框");
    alertBtn->setIcon(QIcon(":/pic/message/alert.png"));
    connect(alertBtn, &QPushButton::clicked, this,
            [=]()
            {
                MessageDialog* w = new MessageDialog("标题栏",
                                                     MessageDialog::MSGType::WARNING,
                                                     "这里是警告信息");
                w->setButtonVisualable(MessageDialog::DialogButton::REJECT, false);
                w->show();

            });
    grid->addWidget(alertBtn,8,2,1,1);

    QPushButton *errorBtn = new QPushButton("错误对话框");
    errorBtn->setIcon(QIcon(":/pic/message/delete.png"));
    connect(errorBtn, &QPushButton::clicked, this,
            [=]()
            {
                MessageDialog* w = new MessageDialog("标题栏",
                                                     MessageDialog::MSGType::CRITICAL,
                                                     "这里是严重错误信息");
                w->setButtonVisualable(MessageDialog::DialogButton::REJECT, false);
                w->show();
            });
    grid->addWidget(errorBtn,8,3,1,1);

    setLayout(grid);

}
framelessChildWidget::~framelessChildWidget()
{
}
